using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Episode01
{
    public class GunController : MonoBehaviour
    {
        /// <summary>
        /// 放武器的插槽
        /// </summary>
        public Transform weaponHold;
        /// <summary>
        /// 默认枪预制体
        /// </summary>
        public Gun startingGun;
        /// <summary>
        /// 已经装备的枪
        /// </summary>
        private Gun equipGun;

        private void Start()
        {
            if(null != startingGun)
            {
                EquipGun(startingGun);
            }
        }

        /// <summary>
        /// 装备抢
        /// </summary>
        /// <param name="gunToEquip"></param>
        public void EquipGun(Gun gunToEquip)
        {
            if(null != equipGun)
            {
                Destroy(equipGun.gameObject);
            }
            equipGun = Instantiate(gunToEquip, weaponHold.position, weaponHold.rotation);
            equipGun.transform.parent = weaponHold;
        }

        /// <summary>
        /// 射击
        /// </summary>
        public void Shoot()
        {
            if(null != equipGun)
            {
                equipGun.Shoot();
            }
        }

    }
}

